﻿Ext.define('app.ux.GSE.cdx',
{
    extend: 'Ext.panel.Panel',
    img: '',
    cdx: '',
    mol: '',
    mf: '',
    mw:'',
    ___mol: 'xx',
    width: 400,
    height: 400,
    border: true,
    html: '<div style="color:red; padding:10px;">双击可以启用结构编辑器</div>',
    initComponent: function () {
        var me = this;

        if (!me.mol || me.mol.length < 10) {
            me.mol = '\n  Ketcher 06241615302D 1   1.00000     0.00000     0  \n  \n  0  0  0     0  0            999 V2000  \n M  END';
            me.img = '';
        }

        this.tbar = [
            '->',
            { text: 'Clear', handler: function () { this.clearChemDraw(); }, scope: this }
        ];

        this.listeners = {
            render: function (p) {
                p.getEl().on('dblclick', function () {
                    var win = Ext.create("app.ux.GSE.cdWeb", { title: '>>编辑结构式', mol: me.mol, img: me.img });
                    win.on('afterCommit', function (mol, img,mf,mw) {
                        me.mol = mol;
                        me.img = img;
                        me.mf = mf;
                        me.mw = mw;
                        me.showImg();
                        me.fireEvent('afterCommit', me.mf, me.mw);
                        win.close();
                    });
                    win.show();
                })


            },
            afterrender: function () {
                me.showImg();
            }
        };

        me.callParent();
    },

    clearChemDraw: function () {
        var me = this;
        me.cdx = '';
        me.img = '';
        me.mol = '';
        me.update('<div style="color:red; padding:10px;">双击可以启用结构编辑器</div>');
    },
    showImg: function () {
        var me = this;
        showImg(me.getId(), me.img, 10, 'middle');
    }
})